package marmalius.command.admin;

import marmalius.Player;
import marmalius.command.BaseCommand;
import marmalius.item.ItemService;
import marmalius.item.ItemTemplate;

public class AddItem extends BaseCommand {

	public void process(Player player, String[] command) {
		if (command == null || command.length < 1) {
			showHelp(player);
			return ;
		}
		
		int itemID = ParseInteger(command[0]);
		ItemTemplate item = ItemService.getInstance().getItemTemplate(itemID);
		if (item != null) {
			int count = 1;
			if (command.length == 2)
				count = ParseInteger(command[1]);
			if (count > 0) {
				int left = player.getInventory().addItem(itemID, count);
				player.sendPlayerMessage("You receive [" + item.getName() + "] x"+(count - left));
			}
			else if (count < 0) {
				int left = player.getInventory().removeItem(itemID, -count);
				player.sendPlayerMessage("You remove [" + item.getName() + "] x"+(-count -left));
			}
		}
		else
			player.sendPlayerMessage("Item not found.");
	}
	
}
